<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/4/26
 * Time: 9:24
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Meet extends Base {
    /***
     * @return mixed|\think\response\Json
     * 首页
     */
    public function index(){
        if(request()->isAjax()){
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('reward')->count();// 获取总条数
            $lists = Db::name('reward')
                ->page($NowPage,$limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    /***
     * @return mixed|\think\response\Json
     * 添加
     */
    public function add(){
        if(Request::instance()->isPost()){
            $reward_price =input('reward_price');
            $data['reward_price'] =$reward_price;
            $data['reward_time'] =date('Y-m-d H:i:s',time());
            $res = Db::table('up_reward')->insert($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        return $this->fetch();
    }

    /***
     * @return mixed|\think\response\Json
     * 编辑
     */
    public function update(){
        if(Request::instance()->isPost()){
            $id = input('id');
            $reward_price =input('reward_price');
            $data['reward_price'] =$reward_price;
            $res = Db::table('up_reward')->where('reward_id',$id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $id = input('reward_id');
        $info= Db::table('up_reward')->where('reward_id',$id)->find();
        $this->assign('id',$id);
        $this->assign('res',$info);
        return $this->fetch();
    }

    /***
     * @return \think\response\Json
     * 删除
     */
    public function del(){
        $task_id = input('param.id');
        $res = Db::name('reward')->where('reward_id',$task_id)->delete();
        if($res){
            return json(['code'=>200,'msg'=>'删除成功']);
        }else{
            return json(['code'=>100,'msg'=>'删除失败']);
        }
    }
}